package net.kts.attraction.subway.adapter;

import java.util.List;

import net.kts.attraction.search.model.Address;
import net.kts.attraction.search.model.LocationFavorite;
import net.kts.attraction.subway.SubwayListActivity;
import net.kts.main.R;

import android.content.Context;
import android.content.Intent;
import android.opengl.Visibility;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class AttractionFavoriteAdapter extends ArrayAdapter<LocationFavorite> {

	public AttractionFavoriteAdapter(Context context, int textViewResourceId,
			List<LocationFavorite> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		View v = convertView;
		
		final LocationFavorite favorite = getItem(position);
		
		
		if (v == null) {
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.attractioni_main_favorite_row, null);
        }
		
		TextView name = (TextView)v.findViewById(R.id.favorite_name);
		TextView nameTrans = (TextView)v.findViewById(R.id.favorite_name_trans);
		TextView favoDate = (TextView)v.findViewById(R.id.favorite_date);
		
		Button button = (Button) v.findViewById(R.id.favoriteGuideBtn);
		button.setFocusable(false);
		
		if(favorite.getSeq() < 0) {
			
			name.setText("favorite not found");
			nameTrans.setText("");
			favoDate.setText("");
			button.setVisibility(View.INVISIBLE	);

			return v;
		}
		
		
		name.setText(favorite.getLocationNameKr());
		nameTrans.setText(favorite.getLocationName());
		favoDate.setText(favorite.getRegistDate());
		
		
		button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Address address = new Address();
				address.setLatitude(String.valueOf(favorite.getLatitude()));
				address.setLongitude(String.valueOf(favorite.getLongitude()));
				
				Bundle bundle = new Bundle();
				bundle.putSerializable("address", address);
				
				Intent intent = new Intent(getContext(), SubwayListActivity.class);
				intent.putExtras(bundle);
				
				getContext().startActivity(intent);
				
			}
		});
		
		
		
		
		return v;
	}
	
	

}
